Html selects last variable option - html

im very new to html and am making a basic rock paper scissor page where you can select the image to choose your action. My issue is that it always selects the last option in the html.
<form action="/result <%#choice = "rock"%>">
<div id="rock_button" class="slideRight">
<input type="image" src="http://i.imgur.com/XT41ZXk.jpg" alt="Rock";>
</div>
</form>
<form action="/result <%#choice = "paper"%>">
<div id="paper_button" class="slideUp">
<input type="image" src="http://i.imgur.com/r1GckhD.jpg" alt="Paper";>
</div>
</form>
<form action="/result <%#choice = "scissors"%>">
<div id="scissors_button" class="slideLeft">
<input type="image" src="http://i.imgur.com/ttUlD5y.jpg" alt="Scissors";>
</div>
</form>
So from the above code, #choice is always set to "scissors". regardless of which picture is clicked on. ive tried putting onclick="<%#choice = "paper"%>" within th input, without any luck and creating one large form for all three picures but nothing has worked. Thanks for any help provided.

The choice variable is only used within the current page: Before any of the images is even clicked.
Use one form. Use buttons. Give them a name and a value. Read the form data in the server side program that acts as your form handler.
<form action="/result">
<button id="rock_button" class="slideRight" name="choice" value="rock">
<img src="http://i.imgur.com/XT41ZXk.jpg" alt="Rock">
</button>
<button id="paper_button" class="slideUp" name="choice" value="paper">
<img src="http://i.imgur.com/r1GckhD.jpg" alt="Paper">
</button>
<button id="scissors_button" class="slideLeft" name="choice" value="scissors">
<img src="http://i.imgur.com/ttUlD5y.jpg" alt="Scissors">
</button>
</form>
Then, in the program that handles the /result URL, you would do something along the lines of:
my $choice = $c->request->params->{choice};
The specifics depending on your choice of server side language.

Related

How to add two dropzone in one form

My html code is
<form action="http://localhost:5000/fileUpload" method="POST" enctype="multipart/form-data">
<div class="dropzone">
<div class="fallback">
<input id="fileContent" name="Content" type="file" multiple />
</div>
<div class="dropzone">
<div class="fallback">
<input id="fileStyle" name="Style" type="file" />
</div>
</div>
<input class="btn btn-primary" name="submit" type="submit" value="Submit"></button>
</form>
and the div tag is does not inherit the drag and drop properties until and unless there is some value set to the action attribute.
basically i want two input to take two different files that is why i want two drag and drop boxes or inputs
You must set some value to the action attribute. The action attribute specifies where to send the form-data when a form is submitted. So if you don't specify the action attribute, the dragged and dropped files definitely wouldn't find any destination after submit button is clicked.
If that is not your main problem you might wanna go through this link about Plupload library for using multiple dropzones.

<a> link wont open in the same page

I have an <a> link which will only open if I right click it and click on "open in a new tab. If i just click it normally it just puts a "?" after the rest of the link, like this: "http://localhost:8011/login.html?".
Code:
<div class="login-page">
<div class="form">
<form class="login-form">
<input type="text" placeholder="Username" />
<input type="password" placeholder="Password" />
<button class="login">login</button>
<p class="message">Not registered? Create an account</p>
</form>
</div>
</div>
If i put target="_self" it still doesn't work. The two files are definitely in the same folder.
Your HTML is invalid. It is forbidden to put a <button> inside an <a>. Use a validator.
The effect you see is due to error recovery reacting badly and your clicks being handled by different elements.
will only open if I right click it and click on "open in a new tab
This is what happens when you right click on the <a> element.
If i just click it normally it just puts a "?" after the rest of the link
This is what happens when you submit a form using a submit button (and the form has no successful controls in it, which is the case here because none of your controls have names).
If you want a link, then use a link and only a link. Get rid of the <button> element.
If you want something that looks like a button then first think about what message you are sending to the user. Buttons do things. Links go places. Giving the user a visual signal that they are doing something is likely to be wrong.
If you still want a link that looks like a button, then style it with CSS.
That said, having a link marked Login which doesn't submit the form is just confusing. You should probably:
Keep the <button>
Get rid of the <a>
Give your form controls name attributes
Make the form use method="POST"
… and then write server side code to process the data so the login form can be used to login to the site.
You can change your HTML form to be as follows so that the form is submitted when login is clicked:
<div class="form">
<form class="login-form" method="POST" action="index.html">
<!-- user inputs -->
<input type="text" name="username" placeholder="Username" />
<input type="password" name="password" placeholder="Password" />
<!-- your submit button -->
<input type="submit" name="submit" value="login">
<!-- your other link -->
<p class="message">Not registered? Create an account</p>
</form>
</div>
This approach will be better than the current one for creating a login form.
This way you still have your button that will redirect to index.html without having to use a messy approach with <a> and <button>.
It's because you've a button, and it's trying to submit the form.
Try using bootstrap and give the <a> tag some classes, like this:
<div class="login-page">
<div class="form">
<form class="login-form">
<input type="text" placeholder="Username" />
<input type="password" placeholder="Password" />
login
<p class="message">Not registered? Create an account</p>
</form>
</div>
</div>
Or just give style to your <a> by css, but if you use the button, then you're submitting the form instead clicking the link.
EDIT: you could also wrap the <a> inside the button, so the link on the <a> will execute first instead of submitting the form
<button class="login">login</button>

Form not working on Mobile Device

I created a website called diditdrop.com. Within the website there is a form where the user enters a number and then submits the number. On the desktop version of the site, the form works great. On the mobile version, the form is not responsive (i.e. i tap on the screen and nothing focuses or pops up. Additionally, the button underneath it doesn't work either).
I'm not sure what to do. I've been stuck on it for a few hours now. I've pasted a snippet of my code below, however, it doesn't look too strange. If someone could take a look at my site, and then recommend a better way of implementing, I would sincerely appreciate it.
<form class = "form-inline" action="https://formspree.io/x#gmail.com" method="POST">
<div class= "form-group">
<span>
<input type="tel" id = "form1" placeholder="digits here" tabindex="1" class="boxed form-control" name="number"/><br>
</span>
<span>
<input type="submit" id = "buttonmove" class="btn boxed" value="get dat new new"name="number" />
</span>
</div>
</form>
Add the following code it will work:
add the style="float:left" to the image like below
<div id="pictureface" class="col-lg-6">
<img style="float:left" class="img-responsive" src="http://static.stereogum.com/uploads/2016/09/CtUYD4uWYAIB1MH-1475280486.jpg">
</div>

POST when clicking an image

I have a "delete" icon with a relative position in the upper-right corner of a photo. When the icon is clicked, the photo should be deleted on the server.
According to HTTP conventions, this is a destructive action which should be done with POST. So a normal <img href> can not be used since it will cause a GET, which is more insecure.
What is the simplest way to make the icon perform a POST that does not exclude Internet Explorer 8? I am currently looking at:
<form method="post" action="script.php">
<img src="photo.jpg"/>
<input name="delete" type="image" src="/image/delete.png"/>
</form>
Or, is it acceptable to use a href in this situation?
(EDIT: Is it more acceptable when the script is only available to an authenticated administrator?)
you should use this code
<form method="post" action="script.php">
<button type="submit" style="background:photo.jpg"/>
<input name="delete" type="image" src="/image/delete.png"/>
</form>
so you can use your photo as background,because when you want submit a form you shold have a input or button whith type submit
<button type="submit" name="testsubmit" value="click"
style="border:none; background-color:transparent;">
<img src="button.png" alt="test image submit" />
</button>

how to validate the pattern in form submit

At the time of given the input in edittext field it show error if anyone will put incorrent IP Address format of IP adsress should be like these 000.000.0.000 plz help me out
IN HTML5:-
<div data-role="content">
<form id="form">
<div data-role="fieldcontain">
<label for="ip">IP Address/System Name</label>
<input name="ip" id="ip" type="text" pattern="((^|\.)((25[0-5])|(2[0-4]\d)|(1\d\d)|([1-9]?\d))){4}$">
</div>
<div style="text-align:center;">
<div data-role="button" data-theme="b" data-inline="true" id="button1">Update</div>
</div>
</div>
For HTML5 validation to work on submit, You have to put required attribute in your input fields, you want to validate using HTML5 and you have to submit the form.
You can handle the form data submitted through javascript, and incase you do want to handle the submitted data manually then you have to specify data-ajax="false" in you form tag
For your code, try this
<div data-role="content">
<form id="form" data-ajax="false">
<div data-role="fieldcontain">
<label for="ip">IP Address/System Name</label>
<input name="ip" id="ip" type="text" required pattern="((^|\.)((25[0-5])|(2[0-4]\d)|(1\d\d)|([1-9]?\d))){4}$">
</div>
<div style="text-align:center;">
<input type="submit" value="Submit button" />
</div>
</form>
</div>
And in javascript you can do something like
$("#form").submit(function(e){
e.preventDefault();
//call your method
});
One route you can go uses mask.js - In your case you can have it force the user to input their data in the proper format, pre-populate the '.' characters in the IP, and stop the user from entering non-numeric values.
Mask.js
And here is a fiddle - http://jsfiddle.net/QF9Lz/2/
click in the textbox, you'll see a formatting mask appear and you will only be able to enter numeric values in the format you specified.
So, once you include mask.js in the head, you can initialize the input mask like this:
$(document).ready( function() {
$('#ip').mask('999.999.9.999');
});
I made this regex for address/mask
For example: 10.0.0.0/8
((25[0-5])|(2[0-4]\d)|(1\d\d)|([1-9]?\d))((^|\.)((25[0-5])|(2[0-4]\d)|(1\d\d)|([1-9]?\d))){3}\/([1-2][0-9]|[0-9]|3[0-2])$
if you want just the regex of address use:
((25[0-5])|(2[0-4]\d)|(1\d\d)|([1-9]?\d))((^|\.)((25[0-5])|(2[0-4]\d)|(1\d\d)|([1-9]?\d))){3}$