/    Sign up×
Community /Pin to ProfileBookmark

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):

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

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 –>

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@PadonakMay 09.2013 — [I]document.write('<form name="form" method="post" action="/search_results.php?find=" + document.getElementById(searchingtext).value">');[/I]

this can not work because:

  • 1. [B]document.write[/B] works before the document is fully loaded but [B]document.getElementById[/B] works after that moment.


  • 2. document.getElementById(searchingtext).value is missing quotes ----> document.getElementById([B]"[/B]searchingtext[B]"[/B]).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 [B]/>[/B] in the end but others have just [B]>[/B] - it's interesting why so?


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


  • etc.
    Copy linkTweet thisAlerts:
    @EwittliauthorMay 09.2013 — 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)...
    Copy linkTweet thisAlerts:
    @PadonakMay 09.2013 — 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 [B]find[/B] variable just change name and id of the text input into [B]find[/B]:

    document.write('&lt;input name="find" id="find" type="text" size="15" value="" class="searchsiteform"&gt;');

    and let the action attribute of the form be just [B]action="/search_results.php"[/B]
    Copy linkTweet thisAlerts:
    @EwittliauthorMay 09.2013 — 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)...
    Copy linkTweet thisAlerts:
    @EwittliauthorMay 09.2013 — 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"
    Copy linkTweet thisAlerts:
    @EwittliauthorMay 09.2013 — 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)...
    Copy linkTweet thisAlerts:
    @PadonakMay 10.2013 — well if you dont want to submit the form usual way |scratching his head|... try something like this:

    <i>
    </i>document.write('&lt;form name="form" method="post" action="/search_results.php?find=" onsubmit="this.action=this.action + document.getElementById("searchingtext").value + '"&gt;');
    ×

    Success!

    Help @Ewittli spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.28,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...