Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using an html form to change a php variable

Status
Not open for further replies.

jefargrafx

Instructor
Joined
May 24, 2001
Messages
273
Location
US
I'd like to create one php page that displays three different input forms.

I'm using the jump menu object and I'd like the php script to include a file depending on the user selection in the jump menu. I can do this on diffent pages, but I want to try and make it all happen on one page.

here's what i got so far:

<?php echo &quot;<?xml version=\&quot;1.0\&quot; encoding=\&quot;iso-8859-1\&quot;?&quot;.&quot;>&quot;; ?>
<!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;<html xmlns=&quot;<head>
<title>Untitled Document</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot; />
<script language=&quot;JavaScript&quot; type=&quot;text/JavaScript&quot;>
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+&quot;.location='&quot;+selObj.options[selObj.selectedIndex].value+&quot;'&quot;);
if (restore) selObj.selectedIndex=0;
}

function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf(&quot;?&quot;))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers.document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_jumpMenuGo(selName,targ,restore){ //v3.0
var selObj = MM_findObj(selName); if (selObj) MM_jumpMenu(targ,selObj,restore);
}
//-->
</script>
</head>

<body><form action=&quot;select_user_type&quot; method=&quot;get&quot; name=&quot;select_user_type&quot; target=&quot;_self&quot;>
<p>
<select name=&quot;select&quot; onchange=&quot;MM_jumpMenu('parent',this,0)&quot;>
<option selected=&quot;selected&quot;>Administrator</option>
<option>Reviewer</option>
<option>News and Articles Contributor</option>
</select>
<input type=&quot;button&quot; name=&quot;Button1&quot; value=&quot;Go&quot; onclick=&quot;MM_jumpMenuGo('select_user_type','parent',0)&quot; />
</p>
</form>

<p>
<?php
$select_user_type = $HTTP_GET_VARS[&quot;select_user_type&quot;];
if ($HTTP_GET_VARS[&quot;select_user_type&quot;] == &quot;Administrator&quot;) {
include('create_administrator.php');
}
if ($HTTP_GET_VARS[&quot;select_user_type&quot;] == &quot;Reviewer&quot;) {
include('create_reviewer.php');
}
if ($HTTP_GET_VARS[&quot;select_user_type&quot;] == &quot;News and Articles Contributor&quot;) {
include('create_contributor.php');
}
?>
</p>
</body>
</html>



: any ideas

thanks


jef
 
Unfortunately, you didn't post your code inside [ignore]
Code:
...
[/ignore] TGML tags, so your array subscript i in your code was interpreted as a TGML tag to begin italics.

In general, you submit the form to a PHP page, which then processes the inputs.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
so I can't pass a variable to the same page and allow the script to dispaly a form depending on that variable?

what about

action=&quot;<?php echo $PHP_SELF?>&quot;

sorry very new to php....I'll get it

jef
 
got it....

just needed to use the request variable statement.

even thou I was post it back to itself....it was still posting

that's for the input



jef
 
okay,

I got another question.

seems we'd like to have my jump menu (drop-down) to keep the selected item when the page returns.

it's posting to itself and I've tried setting the select item to a php variable, but nothing I do gets the item to stay selected.

I hope yall under stand that.

select an item, press go, post back to the same page, display a form (that's working fine), but also, have the menu item selected stay selected, not change back to the first item in the list.

any help

and thanks again

jef
 
You just need to print the &quot;selected&quot; attribute into the <option> tag.
Code:
<option <?php echo($_GET['select']=='Administrator'?&quot;selected&quot;:'';
?>
>Administrator</option>
Same for the other values...
 
okay

just gave this a try?

and this is the error

Parse error: parse error, unexpected ';' in c:\inetpub\ on line 32


syntac look okay to me


<select name=&quot;select_id&quot;>
<option &quot;<?php echo($_GET['select']=='Administrator'?&quot;selected&quot;:'';?>&quot;><?php echo $Administrator ?></option>


jef
 
Do yourself a favor, okay?

Don't use the style of programming where you constantly switch back and forth between execution mode and HTML output mode. It makes debugging code a pain.

Read my FAQ on debugging PHP: faq434-2999

Want the best answers? Ask the best questions: TANSTAAFL!!
 
I can only agree with sleipnir214.
PHP should not be treated as a plug-in wherever you want to have something printed on the page.

Here's where the error comes from:
It looks like ''(two single quotes) which mean print nothing were mistaken for &quot;, a double quote. That will make it a syntax error.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top