www.webdeveloper.com
Results 1 to 8 of 8

Thread: Help with passing an argument from within the following script

  1. #1
    Join Date
    May 2013
    Posts
    5

    Help with passing an argument from within the following script

    The code below is from a ".js" file and I am having problems with figuring out how to concatenate the value from the TEXT FIELD within this code.

    I'm trying to pass an item a person is searching for to another script (like the following):

    http://www.domainname.com/search_result.php?find=dog

    I'm trying to do this in the following line:

    document.write('<form name="form" method="post" action="/search_results.php?find=" + document.getElementById(searchtext).value">');




    <!-- Begin

    if (showsearch == "yes") {

    document.write('<form name="form" method="post" action="/search_results.php?find=" + document.getElementById(searchingtext).value">');

    document.write('<table cellpadding="0" cellspacing="0" border="0" class="sidebartext"><tr><td valign="center">');

    document.write('<font size="2">Search: </font>');

    document.write('<input name="searchtext" id="searchtext" type="text" size="15" value="" class="searchsiteform">');

    document.write('</td><td valign="center">');

    document.write('<input type="hidden" name="searching" value="yes" />');

    document.write('<INPUT TYPE="image" SRC="/assets/images/search-off.gif" name="search" border="0" onmouseover="this.src=\'/assets/images/search-on.gif\'" onmouseout="this.src=\'/assets/images/search-off.gif\'" alt="Search" hspace="3"><br>')

    document.write('</td></tr></TABLE>');

    document.write('</form>');

    }

    // End -->

  2. #2
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,636
    document.write('<form name="form" method="post" action="/search_results.php?find=" + document.getElementById(searchingtext).value">');

    this can not work because:

    1. document.write works before the document is fully loaded but document.getElementById works after that moment.

    2. document.getElementById(searchingtext).value is missing quotes ----> document.getElementById("searchingtext").value

    3. this line of the code has synthax errors. even if it could work, the line had to be written something like this:

    document.write('<form name="form" method="post" action="/search_results.php?find=' + document.getElementById("searchingtext").value + '">');

    4. some of your inputs have /> in the end but others have just > - it's interesting why so?

    5. valign="center" this attr can be baseline|bottom|middle|top it is middle by default

    etc.
    xxx: Guess Buddhist riddle: "What is the sound of one hand clapping?"
    yyy: facepalm

  3. #3
    Join Date
    May 2013
    Posts
    5
    I made the modifications with:

    document.write('<form name="form" method="post" action="/search_results.php?find=' + document.getElementById("searchingtext").value + '">');

    After I uploaded the file the "Search: and Text Box" disappeared.

    Usually this happens if there is a syntax error (can you please look again)?

    the website I am working with is at http://www.clevelandhealth.org/

    Currently, the search is there (I put it back to the way it was just so it would display).

    and I fixed the valign to align (thank you) for point that out (my bad)...

  4. #4
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,636
    sorry my english is not good and often my explanations are not clear. i tried to say that you dont need to have document.getElementById there at all because when document.write works document.getElementById doesn't exist yet. if your php file which does searching expects to get find variable just change name and id of the text input into find:

    Code:
    document.write('<input name="find" id="find" type="text" size="15" value="" class="searchsiteform">');
    and let the action attribute of the form be just action="/search_results.php"
    xxx: Guess Buddhist riddle: "What is the sound of one hand clapping?"
    yyy: facepalm

  5. #5
    Join Date
    May 2013
    Posts
    5
    I made the modifications with:

    document.write('<form name="form" method="post" action="/search_results.php?find=' + document.getElementById("searchingtext").value + '">');

    After I uploaded the file the "Search: and Text Box" disappeared.

    Usually this happens if there is a syntax error (can you please look again)?

    the website I am working with is at http://www.clevelandhealth.org/

    Currently, the search is there (I put it back to the way it was just so it would display).

    and I fixed the valign to align (thank you) for point that out (my bad)...

  6. #6
    Join Date
    May 2013
    Posts
    5
    Yes, if you try the search at http://www.clevelandhealth.org it works (it has been working like that) I need to modify the code so I can pass the aurgument through the hyperlink.

    How can I change this line of code:

    document.write('<form name="form" method="post" action="/search_results.php?find=">');

    so it will get the value from the text box named "find"

  7. #7
    Join Date
    May 2013
    Posts
    5
    Up top I put the following line:

    search_result = document.getElementById("find").value

    Is there a way I can concatenate the variable "search_result" onto the document.write

    So in this case, I'm getting the value of the text box before anything is done (please, I need your help)...

  8. #8
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,636
    well if you dont want to submit the form usual way |scratching his head|... try something like this:

    Code:
    document.write('<form name="form" method="post" action="/search_results.php?find=" onsubmit="this.action=this.action + document.getElementById("searchingtext").value + '">');
    xxx: Guess Buddhist riddle: "What is the sound of one hand clapping?"
    yyy: facepalm

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles