...

View Full Version : How to send input Data on one form to another?



codernoob
09-23-2012, 09:44 PM
Hi,

Is it possible to send input data from one form to another?

Say, I have an Input form for text. I want to send the text as 'Input' to another form which is on a different page.

Can I choose multiple methods to input the data on the first page , but however I choose to enter the form, can this input be transferred as input on the other form?

Thanks!

jmrker
09-23-2012, 10:12 PM
How much data are we talking about?

codernoob
09-23-2012, 10:55 PM
Idea is:

Two options to enter data on the first form which is visible.
Search field on Page 'A' (input option 1)
Search field by Drop down keyword on page A (input option 2).

User inputs 'Search keyword' or choose a 'Preselected Search Keyword' on Page A form.

This keyword entered in the form is sent to page B. Page B is hidden. Page B has a Search input field. The input from A is entered directly to Page B 'Search' Field (form)

Search is performed on Page B and Results is displayed on Page A.

I am kinda lost in ensuring that the keyword entered in A (using the two options) is directly transferred to the form input field of B (displaying results is easier)
does that help?

xelawho
09-23-2012, 10:57 PM
if they're normal sized words the easiest way to do it would be with query strings

codernoob
09-23-2012, 11:01 PM
This would be on a local system without internet/server - only a bunch of PC connected. If my understanding is rt, i would need ASP to get QueryStrings to work?

xelawho
09-23-2012, 11:15 PM
that's not my understanding, but then I have never used a query string on intranet. But any page that you access via url can accept a query string, so I'm guessing that it shouldn't be a drama.

Having just read your question again, though, it seems kind of weird to me... why does page B have to come into it, if the search term is entered on page A and results are displayed on page A?

codernoob
09-23-2012, 11:51 PM
Thanks Xelawho,

The reason am using two pages is related to the fact that I was unable find a code to separate the choice of search.

Below is what am trying on a single page, but this doesnt work as it doesnt know which search input to pick.

Search - by inputing keyword (lets say A-GO)


<form action="ss.html" target="LEFT">
<b>Search this site</b><br>
<input type="text" name="s">
<input type="submit" value="Go">
</form>

AND

Search - by predefined keywords from a drop down list (B-GO)

<select name="s" onClick="return NS()">
<option value=""></option>
<option value="value2">Value 2</option>
<option value="value3">Value 3</option>
</select>

I want the two options to be available in the div, and based on the user choosing either A-GO or B-GO, the results would be displayed using


function C(l){
parent.RIGHT.location.href=l;
}

But this hasnt been possible and i tried quite a few tweaks. So I thought, why not hide the page (B) where actual search happens, and feed that page with inputs using different feeds (from Page A - and input when pressed go)

err, kinda complex to explain...

xelawho
09-23-2012, 11:56 PM
I asked you a clarifying question on this point in this post (http://www.codingforums.com/showthread.php?t=273747) and you never replied - if it's one button for the dropdown and one button for the text input that's easy to keep all on the one page - much easier than what you are proposing, anyway. So is that the deal?

codernoob
09-24-2012, 12:07 AM
i was kinda confused and was trying to find a solution/frame an answer that would clear.

As to what you have mentioned, that would be just fine as well..

Just one button for both options.

But something that worries me from that point is - what if someone has entered a search keyword (say by error) and then chooses an option from the drop down (as well) and then clicks go - which entry would be searched?

Old Pedant
09-24-2012, 12:08 AM
I'm just curious how in the world he is going to do this:


<b>Search this site</b><br>

with a <form> that posts to another HTML page


<form action="ss.html" target="LEFT">

Normally, site searches have to be carried out with server-side code, which an HTML page clearly isn't.

But I agree. He seems to want to make it 3 or 4 times harder than it needs to be, no matter how the search is done.

Old Pedant
09-24-2012, 12:10 AM
]
But something that worries me from that point is - what if someone has entered a search keyword (say by error) and then chooses an option from the drop down (as well) and then clicks go - which entry would be searched?

Depends on how you write the code. You could give precedence to the <select> choice or you could give it to the <input> value. Utterly up to you.

codernoob
09-24-2012, 12:15 AM
I'm just curious how in the world he is going to do this:


<b>Search this site</b><br>

with a <form> that posts to another HTML page


<form action="ss.html" target="LEFT">

Normally, site searches have to be carried out with server-side code, which an HTML page clearly isn't.

But I agree. He seems to want to make it 3 or 4 times harder than it needs to be, no matter how the search is done.


I found this brilliant piece of work online.. which i have tried with my minimal skills to add to my site.

http://www.buildwebsite4u.com/tools/site-search.shtml
but kinda looks like I have used up all the bits I know:

xelawho
09-24-2012, 12:27 AM
as to the preference dilemma, you could make the last element that the user focussed on the one that the code uses for the search term. It's not perfect, but (thinking about it for two seconds) it seems the only problem would be if someone say, entered something in the text, then chose an option from the dropdown, then clicked on the box again for some reason, then clicked the search button.

the bigger concern is making a confusing interface - short of having a little instruction paragraph (which 90% of users are guaranteed not to read), it seems to me that it would be better to have two clearly labelled buttons - "search from input" and "search from options" or some such...

codernoob
09-24-2012, 01:03 AM
yes, I guess having two different buttons will do.. and its a small group who will use this (whom I see everyday)

But from a coding perspective, how should i go about it? As old pendant mentioned, can the code have the possibility of precedence ?

Thanks for your help!!

xelawho
09-24-2012, 01:45 AM
if you have two buttons all you need to do is pass the name of the element that contains the search term to the function and let it sort it out.

Looking at the code you posted in the other thread, I would say that:
1. you name your select "p" and your input "q"

2 you change the onclick for the two buttons to

onClick="return NS('p')"
and

onClick="return NS('q')"
respectively

then you change your NS function to



function NS(el){
if(document.getElementById) document.getElementById('txt').innerHTML=MT(el);
else document.forms[0].submit();
return false;
}


and the first couple of lines of your MT function to



function MT(el){
var c,i,n,t="",ss="",s=document.forms[0][el].value.toLowerCase()+' ';


at which point it seems you're good to go. I'm not sure, though - the code posted in the other thread was incomplete, so it's hard to test, but that seems to be it.

Old Pedant
09-24-2012, 03:19 AM
You should be aware that the ss.exe you are using is a program that does nothing more than create a list of the files on your site that you want to have searched.

The actual searching then takes place by loading those files, one at a time, via JavaScript xmlhttp object and then searching for the text in the JS code.

This works, but it is horribly inefficient compared to doing server-side searching. If your site server has PHP/ASP/JSP capabilities, you really should consider using them instead of doing this in JS.

codernoob
09-24-2012, 12:56 PM
if you have two buttons all you need to do is pass the name of the element that contains the search term to the function and let it sort it out.

Looking at the code you posted in the other thread, I would say that:
1. you name your select "p" and your input "q"

2 you change the onclick for the two buttons to

onClick="return NS('p')"
and

onClick="return NS('q')"
respectively

then you change your NS function to



function NS(el){
if(document.getElementById) document.getElementById('txt').innerHTML=MT(el);
else document.forms[0].submit();
return false;
}


and the first couple of lines of your MT function to



function MT(el){
var c,i,n,t="",ss="",s=document.forms[0][el].value.toLowerCase()+' ';


at which point it seems you're good to go. I'm not sure, though - the code posted in the other thread was incomplete, so it's hard to test, but that seems to be it.

Issue I have is the name that I have to use - it has to be 'S' for the code to work. So I reckon I cannot use 'p' and 'q' - i mean different names.

Excuse my ignorance, but will it be possible to set a 'Default' search option - which is Search by typing in words.
and another, which is : IF Default not used, THEN use Select.
But also allowing both buttons to exist at the same time and kick in based on Default user choice or by virtue of the 'IF'/'Then' parameter?
That possible?

xelawho
09-24-2012, 03:14 PM
there's nothing magical about the letter "s". The reason you were told that is because at this line:

s=document.forms[0].s.value.toLowerCase()+' ';
the code looks for the value of the form element with the name "s"

the code I posted above lets it look for the value of "p" or "q", depending on which button was clicked.

but to go the default route, you would leave everything as is, change the name of the select to "q" and change just that line to:


s=document.forms[0].s.value==""?document.forms[0].q.value.toLowerCase()+' ':document.forms[0].s.value.toLowerCase()+' ';

which will grab the selected value of the select box if there is nothing entered in the input box

codernoob
09-25-2012, 11:06 PM
thanks again Xelawho,
Am sorry ... for being so clueless

it worked! and heres a sample link to the site.

http://amchecking.zxq.net/Home/Search/Search.html

Its just a demo that I put up to check..

Thanks!!!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum