Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8238779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:55:47+00:00 2026-06-07T19:55:47+00:00

I have the following code which I’m using to populate form fields. This code

  • 0

I have the following code which I’m using to populate form fields. This code receives a JSON dataset which has been encoded using the PHP json_encode function.

The code works fine for single quotes and double quotes seperately, however there are occassions when I will have single quotes inside double quotes. An example would be text inside a textarea which might say: The man said “I’m going on vacation”.

I’ve read the single quote doesn’t need escaping and the double quotes are being escaped correctly. I’ve copied the JSON code from Firebug into a validator and it comes back correct which makes me think the code below is at fault. The error I’m getting in Firebug is a syntax error. Strangely enough if I have two single quotes (ie. to open and close) the problem no longer exists.

I’ve spent 3 hours looking at this and don’t seem any closer to a resolution. I appeciate all advice as ever! I can provide further code snippets as needed.

$.ajax({
    type: "GET",
    url: "casedata.php",            
    data: {'caseid':'<?php echo($caseid); ?>', 'callid':'<?php echo($_GET['callid']); ?>', 'stage':'thlViewCall'},
    dataType: "json",
    async: false,
    success: function(data){                    
        $.each((data), function(i, e) {                                 
            if($("input[type=text]")) {
                $('#'+i).val(e);
            }
            if($("input[type=select-one]")) {
                $('#'+i+' option').prop("selectedIndex", e);    
            } 
            if($("input[type=select-multiple]")) {                          
                $('#'+i+' option').prop("selectedIndex", e);    
            }
            if($("input[type=radio]")) {
                $('input[name="'+i+'"][value="'+e+'"]').attr('checked', 'checked');
            }
        });
    }
});

Edit:

Apologies, please find the JSON demonstrating this error below:

{"calldate":"06-07-2012","adviserid":"18","service":"THL","dda_sen":"eqa","finalhearing_date":"24-07-2012","reason_for_tribunal":"part_4","next_deadline_description":"before_final_evidence","understanding_paperwork":"1","ability_negotiate":"1","legal_complexity":"1","comments":"test","action":"referred_to_tss_for_telephone_support","bgInfo":"The man said \"I'm going on holiday\"","initialAdvice":"test2","logreceived":"no","monitored":"no","monitoredby":"","monitoreddate":"00-00-0000","monitorednotes":"","legalsupport":"no","legalsupportid":"0","legalsupportdate":"00-00-0000","legalsupportnotes":""}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T19:55:48+00:00Added an answer on June 7, 2026 at 7:55 pm

    I have fixed this and would like to share my result considering the advice I’ve received in multiple questions on multiple topics.

    I found selecting using input[type] very unreliable, for some reason my text fields were being detected as radio boxes causing unwanted results. The simplest way to fix this was to use class selectors applied to my form elements, an example of my code is below:

    if($("[name="+i+"]").is(".textbox, .select")) {
        $("[name="+i+"]").val(e);
    }
    
    if($("[name="+i+"]").is(".radio")) {
        $("input[name="+i+"][value="+e+"]").attr('checked', 'checked');
    }
    

    This evaluates the name of the field passed in the “i” javascript variable, checks the CSS class of the field then sets the value or attribute accordingly. This is very tidy in my opinion and makes CSS styling that bit easier too.

    I hope my explanation cancels out that -1 for missing the JSON to start with 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code which I am are currently using .... Basically, this
I have the following code which is working, I was wondering if this can
I have the following code which downloads video content: WebRequest wreq = (HttpWebRequest)WebRequest.Create(url); using
I have the following code which encodes json in php $arr = array('htmlOutput' =>
I have the following code which works great:- $('.ajax a').click(function() { getpageajax(this.href); return false;
i have the following code which works fine to download image form url .
I have the following code which I'm using to get the user to input
I have the following code which is a private method inside the form and
I have the following code which pulls json data from an ASP.NET page and
i have following code,which does not show me anything #include <iostream> using namespace std;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.