...

View Full Version : pop-up problem with my form



dimitryous
08-30-2006, 02:55 PM
Hi!

I have a problem with my form:

Her is the code:


<form action="<?php
$_GET['css'] = $mycss;
$myurl = $_SERVER['PHP_SELF']."?css=" . @$_GET['css'];
$select = "selected";
?>" method="get" name="my_form" id="my_form_id">
<tr>
<td>My Form :&nbsp;</td>
<td>
Choose your style :&nbsp;
<select name="css" size="1" onChange="this.form.submit();">
<option value="<?php $mycss = "css/" . $mycss_styles['antique'];echo $mycss;?>">antique</option>
<option value="<?php $mycss = "css/" . $mycss_styles['ceramique'];echo $mycss;?>">ceramique</option>
<option value="<?php $mycss = "css/" . $mycss_styles['default'];echo $mycss;?>">default</option>
</select>
</td>
</tr>
</form>

The form itself works perfectly. This form has an action on all my page.

Only problem is that the pop-up does not want to stay to the option (selected item) the user choose 1, 2, or 3.
I believe I have to write some Javascript ...?
Where do I put this script?

Is it possible to write something like:


onChange="this.form.submit();" "this.form.do_something_else();"
to solve my problem ?

TIA

chump2877
08-30-2006, 03:22 PM
<form action="<?php
$_GET['css'] = $mycss;
$myurl = $_SERVER['PHP_SELF']."?css=" . @$_GET['css'];
$select = "selected";
?>" method="get" name="my_form" id="my_form_id">
that code doesn;t give the HTML action attribute a value...it just executes some PHP code, and declares some variables...i think you want:


<form action="<?php
$_GET['css'] = $mycss;
$myurl = $_SERVER['PHP_SELF']."?css=" . $_GET['css'];
$select = "selected";
echo $myurl;
?>" method="get" name="my_form" id="my_form_id">
to make one of your options selected, use (for example):


<option value="<?php $mycss = "css/" . $mycss_styles['antique'];echo $mycss;?>" selected="selected">antique</option>
and this:


<select name="css" size="1" onChange="this.form.submit();">
will submit your form when one of the options in the select menu changes...

Anthony2oo4
08-30-2006, 03:40 PM
dont understand, can you expand please ?

EDIT:
NVM, chump got it lol

dimitryous
08-30-2006, 03:42 PM
Hi!

Your code:

<option value="<?php $mycss = "css/" . $mycss_styles['antique'];echo $mycss;?>" selected="selected">antique</option>
is ok

but does not give the answer: what if the user choose the second one? I want the pop-up to be "ceramique" in my example code. I want this pop-up to be "default" if the user choose the 3rd one and stuck to this value on the page...

Thanks.

dimitryous
08-30-2006, 04:22 PM
dont understand, can you expand please ?

EDIT:
NVM, chump got it lol
Again me... At the top of my page I have:

<link rel="stylesheet" type="text/css" href="<?php print @$_GET['css'] ?>" />
</head>
In the body:

<form action="<?php
$_GET['css'] = $mycss;
$myurl = $_SERVER['PHP_SELF']."?css=" . @$_GET['css'];
?>" method="get" name="my_form" id="my_form_id">
<tr>
<td>My Form :&nbsp;</td>
<td>
Choose your style :&nbsp;
<select name="css" size="1" onChange="this.form.submit();">
<option value="<?php $mycss = "css/" . $mycss_styles['antique'];echo $mycss;?>">antique</option>
<option value="<?php $mycss = "css/" . $mycss_styles['ceramique'];echo $mycss;?>">ceramique</option>
<option value="<?php $mycss = "css/" . $mycss_styles['default'];echo $mycss;?>">default</option>
</select>
</td>
</tr>
</form>
In fact I just want to get the pop-up reflecting the action of the user...

If 1st is his choice, have "antique" selected. If 2nd (ceramique) is his choice, have "ceramique" selected etc... after his action and stay there until a new choice.

My script is probably not appropriate... May be Javascript do that. But I just don't know how to in Javascript ...

Thanks to all and for hints. I hope being a bit more precise...

chump2877
08-30-2006, 04:43 PM
Doesn;t look like you need javascript if the form is just submitting to the same page:



<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get" name="my_form">
<tr>
<td>My Form :&nbsp;</td>
<td>
Choose your style :&nbsp;
<select name="css" size="1">
<option value="<?php

$option1 = "css/" . $mycss_styles['antique'];
echo $option1;

?>" <?

if ($_GET['css'] == $option1)
echo 'selected="selected"';

?>>antique</option>
<option value="<?php

$option2 = "css/" . $mycss_styles['ceramique'];
echo $option2;

?>" <?

if ($_GET['css'] == $option2)
echo 'selected="selected"';

?>>ceramique</option>
<option value="<?php

$option3 = "css/" . $mycss_styles['default'];
echo $option3;

?>" <?

if ($_GET['css'] == $option3)
echo 'selected="selected"';

?>>default</option>
</select>
</td>
</tr>
</form>

chump2877
08-30-2006, 05:16 PM
here's a more efficient way to do that:


<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get" name="my_form">
<tr>
<td>My Form :&nbsp;</td>
<td>
Choose your style :&nbsp;
<select name="css" size="1"><?

foreach ($mycss_styles as $key => $val)
{
$option1 = "css/".$val;
echo '<option value="'.$option1.'" ';

if ($_GET['css'] == $option1)
{
echo 'selected="selected"';
}

echo ">$key</option>";
}

?></select>
</td>
</tr>
</form>
the code is far less confusing that way...

dimitryous
08-30-2006, 05:51 PM
here's a more efficient way to do that:


<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get" name="my_form">
<tr>
<td>My Form :&nbsp;</td>
<td>
Choose your style :&nbsp;
<select name="css" size="1"><?

foreach ($mycss_styles as $key => $val)
{
$option1 = "css/".$val;
echo '<option value="'.$option1.'" ';

if ($_GET['css'] == $option1)
{
echo 'selected="selected"';
}

echo ">$key</option>";
}

?></select>
</td>
</tr>
</form>
the code is far less confusing that way...

Thanks you Chump2877, You Got It Right!

You miss
<select name="css" size="1" onChange="this.form.submit();">

Keep on the good work!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum