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.

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)

Hiya dude,

 

Yea crucial lol doesn't run otherwise lol,

 

And lol yea it shows maybe abit too much information lmao :),

 

It works when i am not echoing it but when i do bang blows up in my face lol.

 

Many thanks,

 

James.

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?

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.

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>';

}
}
?>

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)

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.