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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is javascript the best option here?

Status
Not open for further replies.
May 13, 2005
56
US
Hi there, I have a form that I am working on that uses PHP to populate 2 listboxes with info from a mySQL db.

in each listbox, you can select a item and click a button (calls a JS function) and move the selected item to a listbox directly below it.

Now, the top left listbox has a drop down select box above it that onChange calls a JS function that changes part of the URL to display different data in that listbox from the db.

My question: When this drop down is selected, it refreshes the page and any thing that was moved into the lower boxes is removed.

I was thinking I could use cookies to store the data in the lower boxes if the user refreshes the page, but I was wondering if I could add any JS to the onChange event that would select and grab the data in the lower boxes and pass it back to the same form?

I also have a submit button on this form that when clicked passes all info from the lower boxes to another php form..

Does that make sense? Any ideas?

Thanks..

Mike
 
Instead of refreshing the page onchange, why not submit the form instead, and pick up on the lower listbox items server-side? That'd be a far better way of doing it, IMHO.

Hope this helps,
Dan



[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Ok, that sounds like a good idea,

What are your thoughts on capturing the data in the bottom box when I go to submit the form to the new page?

Currently in my <form> tags, I have the action=newform.php for example.

is there a way for the onChange event to resubmit to the current page and the Submit button at the bottom to submit to another page?

Or should I set up a select statement, for example

select
case 1:
Show current form

case 2:
show new form


I think that might work, right?

 
Sorry, obviously I am pretty new at this and probably not explaining it correct, or my idea of the way it works is off.

I get what you are saying about submitting the whole form back to itself, thats no problem.
Would I be correct in saying the <form> tags would look like this
Code:
<form method="POST" action="thisform.php">
listboxes etc...
</form>

So, at this point, whenever I submit the form I will be good, but where I think I will have a problem is when I need to submit the same data on the same form to another form?

I would need to change <form method="POST" action="thisform.php"> to <form method="POST" action="thatform.php">

right?


Does that make sense?

Thank you for your help.

Mike
 
Ok,

I think that I will use a select case or if statement once the form is submitted to find out how it was submitted, then display the correct form.

Something like this
Code:
<form action="thisform.php" method="POST">
<input type="submit" value="A" name="test" />
<input type="submit" value="B" name="test" />
</form>

<?
if ($_POST['test'][0] == "A"){
    print "Here are the results for A";
}else{
    print "Here are the results for B";
}

?>

Thanks for you help.

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top