Jump to content

html problem

buklu

how do i permit to select twp campus?how do i clear the Name using reset function?

here's my code:

 

<html>
<head></head>
<body>

    <h1>IVE</h1>
    

    <img src="logo.gif"/>
<p>
        <ul><li>Home</li></ul>
        <ul><li><a href="#">Contact Us</a></li></ul>
</p>

<p>
    Name:<input type="text" />
</p>

<form>
<p>
    Selection Dapartment:
    <input type="radio" name="ans" value="I"/>IT
    <input type="radio" name="ans" value="D"/>Design
</p>    
    

<p>
    Name
    <select>
        <option>1</option>
        <option>2</option>
        <option>3</option>
    </select>
    
</p>

<p>
    Select two Campus:
        <input type="checkbox" checked="checked"/>Chai Wan
        <input type="checkbox"/>Tsing Yi
        <input type="checkbox"/>Lee Wai Lee 
        
</p>
    
    <input type="submit" value="Submit"/>
    <input type="reset" value="Clear"/>
    
</form>
</body>
</html>

na.PNG

Link to comment
Share on other sites

Link to post
Share on other sites

With a little help from jQuery you can limit selected checkboxes to 2.

Also, for input type=reset to work with select, you must specify one default value (if you don't want default value to be selectable, just make it disabled). Check this link: https://jsfiddle.net/vy37Lm5t/

Link to comment
Share on other sites

Link to post
Share on other sites

Here's non-jQuery-dependent code:

<!-- wrap the checkboxes in something like a div -->
<div>
        <input type="checkbox" checked="checked" onchange="check(this)"/>Chai Wan
        <input type="checkbox" onchange="check(this)"/>Tsing Yi
        <input type="checkbox" onchange="check(this)"/>Lee Wai Lee 
</div>

<script>
  function check(el) {
    if(el.checked && el.parentNode.querySelectorAll("input:checked").length > 2)
      el.checked = false;
  }
</script>

Note that you should also check if there's less than 3 selected on the server side

🙂

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×