Jump to content

[SOLVED] How do i make javascript work inside a php echo ?


jamesxg1

Recommended Posts

Hiya guy's,

 

I have this,

 

<?php
while($det = mysql_fetch_array($Dets)) {

if(isset($det['name']) && isset($_GET['busid'])) {

//THIS BIT WORKS

echo '<label class="description" for="element_11"><img src="images/green_tick.gif" width="18" height="18"> You have selected ' . $det['name'] . '.</label>';
echo '<input id="busid" name= "busid" class="element text" maxlength="255" size="8" value="' . $det['id'] . '" type="hidden"/>';
echo '<input id="busname" name= "busname" class="element text" maxlength="255" size="8" value="' . $det['name'] . '" type="hidden"/><div></div>';

} else {

//THIS DONT (JAVASCRIPT:AUTOSUGGEST()) IS WHAT ISNT WORKING.

echo '<label class="description" for="element_11">Type To Search: </label><div><input name="search-q" id="search-q" type="text" class="element text medium" value="" onkeyup="javascript:autosuggest()"/></div>';

}
}
?>

 

I have labeled the areas, would someone assist here on helping me please,

 

Many thanks,

 

James.

Link to comment
Share on other sites

does it need to have 'javascript:' part?

echo '<label class="description" for="element_11">Type To Search: </label><div><input name="search-q" id="search-q" type="text" class="element text medium" value="" onkeyup="autosuggest();" /></div>';

 

I also assume that actual function is coded somewhere I couldn't see  8)

Link to comment
Share on other sites

Faults, Because i am echoing it it doesn't even show the input box lol.

 

Many thanks,

 

James.

 

lmao, didn't mention it was not being displayed at all

 

That line

echo '<label class="description" for="element_11">Type To Search: </label><div><input name="search-q" id="search-q" type="text" class="element text medium" value="" onkeyup="javascript:autosuggest()"/></div>';

displays fine on my server... does this

if(isset($det['name']) && isset($_GET['busid'])) {

actually return false at any stage?

Link to comment
Share on other sites

Faults, Because i am echoing it it doesn't even show the input box lol.

 

Many thanks,

 

James.

 

lmao, didn't mention it was not being displayed at all

 

That line

echo '<label class="description" for="element_11">Type To Search: </label><div><input name="search-q" id="search-q" type="text" class="element text medium" value="" onkeyup="javascript:autosuggest()"/></div>';

displays fine on my server... does this

if(isset($det['name']) && isset($_GET['busid'])) {

actually return false at any stage?

 

Lmfao :D, Nope nothing lol,

 

The if statement works i just cant seem to understand why the java isn't,

 

I think and this is only a hunch but i think the enders might be muddled ( } )  and the else statement is in the wrong place :),

 

Many thanks,

 

James.

Link to comment
Share on other sites

So the second choice of the else statement is returned at some point?

 

<?php
while($det = mysql_fetch_array($Dets)) {
/* 
* we will change this to check it 
*/
if(isset($somethingthatdoesnotexist)) {

//THIS BIT WORKS - but wont now

echo '<label class="description" for="element_11"><img src="images/green_tick.gif" width="18" height="18"> You have selected ' . $det['name'] . '.</label>';
echo '<input id="busid" name= "busid" class="element text" maxlength="255" size="8" value="' . $det['id'] . '" type="hidden"/>';
echo '<input id="busname" name= "busname" class="element text" maxlength="255" size="8" value="' . $det['name'] . '" type="hidden"/><div></div>';

} else {

//THIS DONT (JAVASCRIPT:AUTOSUGGEST()) IS WHAT ISNT WORKING.
/*
*
* THIS BIT IS ACTUALLY BEING OUTPUTTED RIGHT??
* lets check by changing something above ^^^^^^^^^^^
*/
echo '<label class="description" for="element_11">Type To Search: </label><div><input name="search-q" id="search-q" type="text" class="element text medium" value="" onkeyup="javascript:autosuggest()"/></div>';

}
}
?>

Link to comment
Share on other sites

This works fine for me

 

<?php
$i=0;
while($i<3) {
/* 
* we will change this to check it 
*/
if(isset($somethingthatdoesnotexist)) {

//THIS BIT WORKS - but wont now

echo '<label class="description" for="element_11"><img src="images/green_tick.gif" width="18" height="18"> You have selected ' . $det['name'] . '.</label>';
echo '<input id="busid" name= "busid" class="element text" maxlength="255" size="8" value="' . $det['id'] . '" type="hidden"/>';
echo '<input id="busname" name= "busname" class="element text" maxlength="255" size="8" value="' . $det['name'] . '" type="hidden"/><div></div>';

} else {

//THIS DONT (JAVASCRIPT:AUTOSUGGEST()) IS WHAT ISNT WORKING.
/*
*
* THIS BIT IS ACTUALLY BEING OUTPUTTED RIGHT??
* lets check by changing something above ^^^^^^^^^^^
*/
$echo '<label class="description" for="element_11">Type To Search: </label><div><input name="search-q" id="search-q" type="text" class="element text medium" value="" onkeyup="javascript:autosuggest()"/></div>';

}
$i++;
}
?>

 

so I guess you know where to look  8)

Link to comment
Share on other sites

This works fine for me

 

<?php
$i=0;
while($i<3) {
/* 
* we will change this to check it 
*/
if(isset($somethingthatdoesnotexist)) {

//THIS BIT WORKS - but wont now

echo '<label class="description" for="element_11"><img src="images/green_tick.gif" width="18" height="18"> You have selected ' . $det['name'] . '.</label>';
echo '<input id="busid" name= "busid" class="element text" maxlength="255" size="8" value="' . $det['id'] . '" type="hidden"/>';
echo '<input id="busname" name= "busname" class="element text" maxlength="255" size="8" value="' . $det['name'] . '" type="hidden"/><div></div>';

} else {

//THIS DONT (JAVASCRIPT:AUTOSUGGEST()) IS WHAT ISNT WORKING.
/*
*
* THIS BIT IS ACTUALLY BEING OUTPUTTED RIGHT??
* lets check by changing something above ^^^^^^^^^^^
*/
$echo '<label class="description" for="element_11">Type To Search: </label><div><input name="search-q" id="search-q" type="text" class="element text medium" value="" onkeyup="javascript:autosuggest()"/></div>';

}
$i++;
}
?>

 

so I guess you know where to look  8)

 

Nope nothing, not working lol. Jheez this script snippet is a nightmare lmao

Link to comment
Share on other sites

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.