Jump to content

Recommended Posts

Hi everyone,

 

I am trying to read some values from the page calling this function and pass this values from the input fields to the ajax function. Please its giving me erro's i need some urgent help please.

 

 

Here is the code:

 

 

<input type=hidden value="1" id='field_1text>
<input type=text id='field_2text' onclick="javascript: checkmake('field_1text','field_2text')">


function checkmake(check_div1, check_div2) {

if(check_div1 || check_div2)
{
var check_value1 = document.getElementById(check_div1).value;
var check_value2 = document.getElementById(check_div2).value;

MyAjaxRequest("displaymodels","requestmodel.php?amake=$check_value1&amodel=$check_value2");
}
else
{
var check_value1 = '';
var check_Value2 = '';
alert("Please select the make first");
}

}

 

This showing me $check_value1 variable in my php file it's not passing the value of check_value1 or check_value2, please help.

I think I see the problem

 

check the following line

MyAjaxRequest("displaymodels","requestmodel.php?amake=$check_value1&amodel=$check_value2");

if I am right $check_value1 $check_value2 are your php variables but your passing it as if they are javascript variables

 

you need to convert this variable to javascript variable first try this:

//pass php values to javascript
var checkValue1="<?php echo($check_value1);?>";
var checkValue2="<?php echo($check_value2);?>";
//ajax request correction
MyAjaxRequest("displaymodels","requestmodel.php?amake="+checkValue1+"&amodel="+checkValue1);

 

oh one thing else i see you have both $check_value1 and check_value1 looks a bit confusing

and in the following line

var check_value1 = document.getElementById(check_div1).value;

 

are you trying to get a value out of a div tag? Don't think div tags are suppose to have the "value" attribute they do have innerHTML so that would look like

var check_value1 = document.getElementById(check_div1).innerHTML;

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.