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 7967897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:59:33+00:00 2026-06-04T06:59:33+00:00

So I had been using this generic code to create a URL from the

  • 0

So I had been using this generic code to create a URL from the form elements

function submiturl() {
    url="Search.do?call=JS"; 
    var elem = document.getElementById('searchInput').elements;
    for(var i = 0; i < elem.length; i++) {
        url = url + "&" + escape(elem[i].name) + "=" + escape(elem[i].value);
    }
    url = url.substring(0,(url.length-1));
   alert(url);
}

however it does not handle checkboxes properly – I only want to add to the URL if the checkboxes are checked. So if you had this html

<html>
<body>
<form name="searchInput" id ="searchInput">
    <input name="first" type="checkbox" value="123"/>One two three
    <input name="second" type="checkbox" value="456"/>Four five six
    <button type="button" onClick="submiturl();">Submit</button>
</form>
</body>
</html>

it will create the URL using the value for both checkboxes regardless if they were checked or not.

So how can I modify my javascript to check if it is a checkbox and is checked?

thanks!

  • 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-06-04T06:59:34+00:00Added an answer on June 4, 2026 at 6:59 am
    function submiturl() {
        var url="Search.do?call=JS", 
            els = document.getElementById("searchInput").elements
        ;
        for(var el, i = 0, n = els.length; i < n; i++) {
            el = els[i];
            if (el.checked || el.type !== "checkbox") {
                url += "&" + encodeURIComponent(el.name) + 
                       "=" + encodeURIComponent(el.value)
                ;
            }
        }
        alert(url);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I reused some old code and come saw that I had been using this
I've been using the following code to move views around, and never had a
To return a file using sinatra, I had been using this: get '/:name' do
Hi there i had been sucessfully using this great library PDF Sharp.now i wanted
Been using this site for ages and have never had to go as far
I have been using this exact Build.xml file. I had problems in the beginning
We are trying to get quaqua out of our application. We had been using
String string1 = abCdefGhijklMnopQrstuvwYz; String string2 = ABC; I had been using string1.startsWith(string2), which
I had been racking my brains over creating a vertical alignment in css using
I've been using prepared statements for a little while now and I've never had

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.