PDA

View Full Version : Convert javascript links to html/php links.



agua
01-09-2007, 01:00 AM
I'm just cleaning up a job for someone and it was built with a javascript jump menu type navigation thing.

I am making to links back into html - but can't work out the syntax - here is the code on the targetted php file:


if (!$resSrch) {
$query = $db->select("select * from rooms order by name");
$result = '';
foreach ($query as $c)
{
$room.="<option value=".$c[id]." ".($productRoom==$c[id]?'selected':'').">".$c["name"]."</option>";
}

How would that look as html?

Also - would the php file still work if I change the link which calls it into action?

Chris
01-09-2007, 09:40 AM
It is hard to say, that isn't the whole story. It is printing out form elements, so we'd need to see the rest of the form and any JS located in the header of the document.

agua
01-09-2007, 06:43 PM
Thanks Chris - I'll investigate further

agua
01-18-2007, 12:16 AM
OK - I've tried to work this out - and I ain't got a clue... If any of you have got time - could you have a look please :confused:

Here is the php I have singled out:
if ($search == 1){

$sql = "select ro.name roname, i.name iname from rooms ro, items i where

".($productItems?"i.id = '$productItems' and " : '')."

ro.id = '$productRoom'";

$s1 = $db->select($sql);
$sql="
select
distinct p.id as id, p.name as pname, p.code as code, p.price, i.name, ra.name, ro.name, p.pic_preview as ppicpreview
from
products as p,
items as i,
ranges as ra,
rooms as ro

where
p.item_id = i.id
and
p.room_id = ro.id
and
p.range_id = ra.id
and
ro.id = '$productRoom' and
p.item_id = '$productItems'
";
// echo $sql;

$smarty->assign("s1Room",$s1[0]["roname"]);
$smarty->assign("s1Item",$s1[0]["iname"]);

Here is the javascript:
<script language="JavaScript">
var items_1=new Array (
'1', 'bookcases',
'16', 'butler tables',
'13', 'coffee tables',
'14', 'hall tables',
'5', 'leather accents',
'12', 'mirrors',
'15', 'side tables',
'8', 'storage and display units',
'9', 'tables',
'10', 'wood accents',
'');

var items_2=new Array (
'1', 'bookcases',
'11', 'chests of drawers',
'6', 'sideboards',
'8', 'storage and display units',
'');

var items_3=new Array (
'1', 'bookcases',
'2', 'chairs',
'13', 'coffee tables',
'14', 'hall tables',
'6', 'sideboards',
'8', 'storage and display units',
'9', 'tables',
'');

var items_4=new Array (
'16', 'butler tables',
'2', 'chairs',
'11', 'chests of drawers',
'13', 'coffee tables',
'17', 'sectionals',
'15', 'side tables',
'7', 'sofas',
'8', 'storage and display units',
'');

var items_5=new Array (
'3', 'home office and entertainment',
'');

var items_6=new Array (
'11', 'chests of drawers',
'');

var items_0=new Array ('');

function freeSelect(sel,dflt){
for(var i=0;sel.options.length>0;i++){
sel.options[0]=null;
}
sel.options[0]=new Option(dflt,'');
}

function changeRoom(form,room)
{
var cb=form.productItems;
freeSelect(cb,'select item');
var items=eval("items_" + room);
for(i=0; i<(items.length-1);i+=2)
{
var opt=new Option(items[i+1],items[i]);
cb.options[cb.options.length]=opt;
}

}

</script> Here is the form:
<form action="searchresults.php" method="post" name=myChoices>
<table align="left">
<tr>
<td width="91" rowspan="4" align="left" valign="top"><img src="/img/join.gif" width="14" height="74" /></td>
<td width="91" height="25" align="left" valign="top"><select id=select5 name=productRoom onchange="changeRoom(this.form,this.value)">
<option value="0">quick find</option>
<option value=1 >Accents</option>
<option value=2 >Cabinets</option>
<option value=6 >Chests</option>
<option value=3 >Dining Room</option>
<option value=4 >Living Room</option>
<option value=5 >Multimedia</option>
</select>
</td>
<td width="28">&nbsp;</td>
</tr>
<tr>
<td align="left" valign="top"><div align="center"><font color="#333333" size="2" face="Arial, Helvetica, sans-serif">and</font></div></td>
<td>&nbsp;</td>
</tr>
<tr>
<td align="left"><select id=select6 name=productItems>
<option value="0">select item</option>
</select>
</td>
<td align="left" valign="top">&nbsp;</td>
</tr>
<tr>
<td align="left" valign="top"><input name="Send22" type="image" value="Send"
src="/img/go.gif" alt="Send" width="28" height="19"
/>
</td>
<td>&nbsp;</td>
</tr>
</table>
<input type=hidden name=search value=1 />
</form>

I did find a link to the "Print this page" which is this:
searchresults.php?print&productRoom=6&productItems=11&Send22_x=13&Send22_y=17&Send22=Send&search=1 - but that doesn't work anyway... so maybe the whole thing doesn't work.

Much appreciated if you can see anything which my untrained eye can't

Cheers

polspoel
01-19-2007, 12:18 PM
I don't see $room being used in the newest code you posted?.. Maybe you can also put an example online (html)

I agree it seems tricky though :)

agua
01-19-2007, 04:29 PM
Thanks for looking polspoel

I forgot to update this post... the whole job was made using Smarty Templates - and we think the original coder has gone Smarty mad - so I'm just remaking it from scratch - it seems like the best solution and will also be easier for future updates.

Thanks again