Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 548493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:05:05+00:00 2026-05-13T11:05:05+00:00

Noob at javascript etc. here. I’m a php/core Java programmer tasked with maintaining a

  • 0

Noob at javascript etc. here. I’m a php/core Java programmer tasked with maintaining a bunch of JS code in JSPs using Struts. What I need to do is simple, but I can’t figure out an easy solution. Given the following code excerpt for a struts’ed HTML form and a JS submit function, I need to modify the text field “query”’s data after the “Submit” button is pressed, but before the data is submitted (tacked on to the page URI). When “submit” is pressed, the page reloads with ?search=whatever_was_typed_in_the_text_box appended to the URL. I need to modify that value: for example, a simple character-replace function: if the user types “apple”, a function replacing all “a” characters with “b” would do the trick, so that when “submit” is pressed with “apple” in the text field, the page redirects to (original-URL)?search=bpple.

I can write the text processing function myself, (I know enough JS for that at least), but I don’t know how to get the input out of the form and modify it after the button is clicked, but before submission. I’ve tried adding “document.forms[SEARCH_FORM_NAME].query.value = replaceChars(document.forms[SEARCH_FORM_NAME].query.value)” to the JS “submitSearch” method, before the actual submission line (with replaceChars as a handwritten simple character-replace method), but it hasn’t changed the data submitted into the URL. I’ve also tried document.getElementById(‘query’).value=…, with the same result.

How would I modify the data from the text field in the form below after the submit button is clicked, but before the form is submitted to the URL?

Code Excerpt:

<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>

<head>


<script type="text/javascript" defer="defer">

    var SEARCH_FORM_NAME = "searchForm";

    function submitSearch() {
        $("sort").value = "filePath";
        $("dir").value = "asc";
        document.forms[SEARCH_FORM_NAME].submit();
        return false;
    }
</script>
</head>

<html:form styleId="searchForm" action="/search" method="get" onsubmit="return submitSearch();">
<table width="100%">
<tr>
    <td style="width:10%;"><tiles:insert page="/WEB-INF/tiles/logo.jsp" /></td>
    <td class = "search-cell" style="width:10%; white-space:nowrap;">            
        <html:text property="query" styleId="query" size="50"/>
        <html:submit onclick="return submitSearch();">
            Search
        </html:submit>
    </td>
</tr>
</table>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T11:05:05+00:00Added an answer on May 13, 2026 at 11:05 am

    You are assigning submitSearch() to the onclick event for the submit button AND the onsubmit event for the form!

    Since the onclick event is fired before the onsubmit event, the onsubmit event will not even fire if the onclick event didn’t return true!!!!

    Get rid of the onclick handler, then it should work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First timer here, and total noob when it comes to PHP and JavaScript. I
Noob here - I'm working on a simple Javascript calculator, and I'm using lists
javascript noob trying to figure something out. I saw a script located here: Using
Total noob here with javascript. I'm trying to alter a function. This is the
Javascript noob here (I'm assuming I will need Javascript to solve this). I need
i'm new here & i'm a noob with javascript, so please, be gentle &
so I am a total php/javascript noob. I'm trying load a full php array
I'm a complete JavaScript noob. I am using this right now: $(function() { $(#tabs).tabs({
javascript noob here. So I'm trying to use this s3 uploader jQuery example here
I'm a noob in Javascript but here is my problem: I'm cleaning up some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.