Two buttons one form - javascript

<?=form_open('blog/register');?>
<table>
<tr>
<td><label for="register_name">Username : </label></td>
<td><input type="text" name="register_name" readonly="readonly" value="<?=$_POST['username']?>"/></td>
</tr>
<tr>
<td><label for="register_email">Email:</label></td>
<td><input type="text" name="register_email" readonly="readonly" value="<?=$_POST['email']?>"/></td>
</tr>
<tr>
<td><label for="register_password">Password:</label></td>
<td><input type="password" name="register_password" readonly="readonly" value="<?=$_POST['password']?>"/></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Register" onclick="return true;"/></td>
</tr>
<tr>
<td></td>
<td>
<input type="button" value="Edit" onclick="window.location.replace('http://localhost/index.php?username='<?=$_POST['username']?>'&email='<?=$_POST['email']?>');return true;"/>
</td>
</tr>
</table>
<?=form_close()?>
That is the form with two buttons as two choices, the Register button is to redirect the user to the registered screen whereas the second button will direct him to the logon screen. It doesn't work, could someone offer me a hint or any instructions please ?
I click the second button and nothing happens. The first button works fine

Try replacing
<input type="button" value="Edit" onclick="window.location.replace('http://localhost/index.php?username='<?=$_POST['username']?>'&email='<?=$_POST['email']?>');return true;"/>
with
<input type="button" value="Edit" onclick="window.location.href = 'http://localhost/index.php?username=<?=$_POST['username']?>&email=<?=$_POST['email']?>';return true;"/>
I believe you have some quotes mixed up.
To clarify, I removed the single quotes around your php because I believe they aren't necessary and cut off your location string at a place you don't want.
The location string that your code produces is 'http://localhost/index.php?username=', which is incorrect.
UPDATE
Changed replace() to href

Replace the code
<input type="button" value="Edit" onclick="window.location.replace('http://localhost/index.php?username='<?=$_POST['username']?>'&email='<?=$_POST['email']?>');return true;"/>
with
<input type="button" value="Edit" onclick="window.location.replace('http://localhost/index.php?username=<?=$_POST['username']?>&email=<?=$_POST['email']?>');return true;"/>

Related

HTML <input> required Attribute not working [duplicate]

This question already has answers here:
Form inside a table
(3 answers)
Closed 3 years ago.
My required attribute which i placed inside a row of a table doesn't seem to be working at all.
I tried closing and un-closing the input tags and changing the button type to input type = "submit" but still the problem persist.
<tr>
<form action="">
<td><input type="text" id="itn" required/></td>
<td> <input type="text" id="prc" required/></td>
<td> <input type="text" id="dt" required/></td>
<td><input type="text" id="qn" required/></td>
<td><input type="text" id="am" required/></td>
<button type="button" onclick="add()" class="button button3">
ADD
</button>
</tr>
When I execute the code on my google chrome browser, the browser doesn't show any alert or warnings if i miss out any fields.
Put you table inside a form. This is a basic example and use action. Inside the add function you can put custom validators and submit the form using ajax
function add() {
}
<form action="add()">
<table>
<tr>
<td><input type="text" id="itn" required/></td>
<td> <input type="text" id="prc" required/></td>
<td> <input type="text" id="dt" required/></td>
<td><input type="text" id="qn" required/></td>
<td><input type="text" id="am" required/></td>
<td><button type="submit" class="button button3">
ADD
</button></td>
</tr>
</table>
Try this code
<tr>
<form action="">
<td><input type="text" id="itn" required/></td>
<td> <input type="text" id="prc" required/></td>
<td> <input type="text" id="dt" required/></td>
<td><input type="text" id="qn" required/></td>
<td><input type="text" id="am" required/></td>
<input type="submit" onclick="add()" class="button button3" value="ADD">
</form>
</tr>

My login page javascript button not working

<center>
<table>
<form method="post" name="login" enctype="application/x-www-form-urlencoded">
<tr>
<td colspan="2" align="center">
<font face="arial" size="5">AreĆ” do Cliente</font>
</td>
</tr>
<tr>
<td>
E-mail:
</td>
<td>
<input type="text" name="credential_0" value="" size="30" maxlength="128" class="formfield">
</td>
</tr>
<tr>
<td>
Senha:
</td>
<td>
<input type="password" naem="credential_1" size="20" maxlength="50" class="formfield">
</td>
</tr>
<tr>
<tr>
<input type="submit" name="Log In" value="Check Mail" onclick="javascript:login.action='https://thewebsite.com/mail/index.bml?s=1';javascript:login.destination.value = '/mailadmin/index.bml?check=1';">
</td>
<td>
<input type="submit" name="Log In" value="Manage Mail" onclick="javascript:login.action='https://thewebsite.com/mailLogin';javascript:login.destination.value = '/mailadmin/index.bml?manage=1';">
</td>
</tr>
<input type="hidden" name="destination">
</form>
</table>
</center>
I am not an expecialist but i don't know much of javascript, also i need a little help on the full code. Check for me if it's all ok!
But my main question is how i make this button open in a new window/tab or set url parent?
https://thewebsite.com/mail/index.bml?s=1';javascript:login.destination.value
= '/mailadmin/index.bml?check=1';" >
<a target="_blank" href="https://www.wikipedia.org/">Wikipedia (opens in a new window)</a>
You can open page in new tab or page by using anchor tag very easily. Like,
The home page will open in another tab.
Read more:
https://html.com/attributes/a-target/#ixzz5Sh13WUpK
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a

Calculation between controls array using jquery

I am creating 2 dynamic controls array.
<input type=text name=quantity[]>
<input type=text name=price[]>
I want to multiply these two inputs and show the result accordingly. I want to do it on frontend using javascript or jQuery.
What will be the best possible way of doing it?
EDIT
#Zeus
As I mentioned in the question it is an array of controls so the code will go like this
<input type="text" name="quantity[]"> <input type="text" name="price[]">
<input type="text" name="quantity[]"> <input type="text" name="price[]">
<input type="text" name="quantity[]"> <input type="text" name="price[]">
Now I will enter quantity in first textfield and price in the second one. For each row I need to multiply these fields and show the result next to them.
Hope it explains the question more.
You can do it like this :
$("button").click(function() {
$("#calc tr").each(function(i) {
var result = $(this).find("input[name*='quantity[]']").val() * $(this).find("input[name*='price[]']").val();
$(this).children("td:nth-child(3)").html(result);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<table id="calc">
<tr>
<th>Quantity</th>
<th>Price</th>
<th>Result</th>
</tr>
<tr>
<td>
<input type="text" name="quantity[]">
</td>
<td>
<input type="text" name="price[]">
</td>
<td></td>
</tr>
<tr>
<td>
<input type="text" name="quantity[]">
</td>
<td>
<input type="text" name="price[]">
</td>
<td></td>
</tr>
<tr>
<td>
<input type="text" name="quantity[]">
</td>
<td>
<input type="text" name="price[]">
</td>
<td></td>
</tr>
</table>
<button>Click me after entering values</button>
Run the code to test it.
This is just an example you will be needing to edit the code to make it work for you.

all the link in my php form direct to the form action

This is my following codes..
<form class="form-horizontal" id="tambah_gps" name="tambah_gps" method="POST" action="../controller/add_gps.php">
<table>
<tr style="height:40px">
<td>Nama User</td>
<td style="width:20px"> : </td>
<td><input class="form-control" type="text" name="nama_user" placeholder=" User Name" style="width:300px" readonly></td>
<td>&nbsp&nbspChoose User</button></td>
</tr>
<tr style="height:40px">
<td>Vehicle ID</td>
<td style="width:20px"> : </td>
<td colspan="2"><input class="form-control" type="text" name="no_polisi" placeholder=" Nomor Polisi Kendaraan"></td>
</tr>
<tr style="height:40px">
<td>Car brand</td>
<td style="width:20px"> : </td>
<td colspan="2"><input class="form-control" type="text" name="merk_mobil" placeholder=" Merk Mobil"></td>
</tr>
<tr style="height:40px">
<td>Color</td>
<td style="width:20px"> : </td>
<td colspan="2"><input class="form-control" type="text" name="warna" placeholder=" Warna"></td>
</tr>
<tr style="height:40px">
<td>GPS Number</td>
<td style="width:20px"> : </td>
<td colspan="2"><input class="form-control" type="text" name="no_telp_gps" placeholder=" nomor telepon GPS"><td>
</tr>
<tr style="height:40px">
<td>Time Zone/td>
<td style="width:20px"> : </td>
<td colspan="2"><input class="form-control" type="text" name="zona_waktu" value="GMT (Default)" placeholder=" Zona Waktu" readonly></td>
</tr>
</table>
<div class="modal-footer">
<button class="btn btn-default" data-dismiss="modal">Cancel</button>
<input type="submit" name="sumbit" value="Save" class="btn btn-primary">
</div>
<form>
The form I made has 3 buttons : 1 Button Save, 1 Button Cancel, and 1 button to choose User Name.. if the button to choose user name clicked, it will open new window that containing user list. the button works pretty well. but whenever it clicked the page always directed to the form action (just like when you click the save button). Can anyone tell me whats wrong with my code? Thank you...
First of all you use your <button> inside of <a> where latter has javascript:void(0) as href. If href is not needed then there no point to put <a> around <button>.
Second &nbps entity MUST end with ;
Third javascript in onclick must be enclosed by " . Single quotes should be used within javascript statement.
And last: you must tell <button> to be exactly what you want it to be: just button! by using type='button'
Therefore the line for your "Choose User" button looks as follows:
<td> <button type="button" class="btn btn-primary" onClick="window.open('pilih_user.php','Ratting','width=1000,height=400,left=200');">Choose User</button></a></td>

Instruction error outside javascript function

I'm making a form with a submit button to check login and a link to make a new user!
I'm coding this with:
<script language="javascript">
function new_user()
{
document.getElementById("login").value='registo';
}
</script>
<form id="frmLogin" name="frmLogin" method="post" action="#">
<table>
<tr>
<td><label for="username">Nome do utilizador</label></td>
<td><input type="text" name="username" id="username" /></td>
</tr>
<tr>
<td><label for="password">Palavra-passe</label></td>
<td><input type="text" name="password" id="password" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="OK" id="OK" value="Submit"/></td>
</tr>
<tr>
<td><input type="hidden" name="login" id="login" value="login"/></td>
<td>Novo Utilizador</td>
</tr>
</table>
</form>
I want to use a hidden field to know if the user pressed the button or the link.
To make the code smaller I'd like to use this code instead:
<form id="frmLogin" name="frmLogin" method="post" action="#">
<table>
<tr>
<td><label for="username">Nome do utilizador</label></td>
<td><input type="text" name="username" id="username" /></td>
</tr>
<tr>
<td><label for="password">Palavra-passe</label></td>
<td><input type="text" name="password" id="password" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="OK" id="OK" value="Submit"/></td>
</tr>
<tr>
<td><input type="hidden" name="login" id="login" value="login"/></td>
<td>Novo Utilizador</td>
</tr>
</table>
</form>
Can anyone explain me why this doesn't work?
You might be having a quote clash in the definition of the onclick event handler. Your browser is interpreting it as onclick="document.getElementById(".
Try enclosing the argument of the document.getElementById sentence in single quotes.
onclick="document.getElementById('login').value='registo';document.frmLogin.submit();">
You can use it as below
<td>Novo Utilizador</td>
use single quote for getElementById that will solve it.

Categories

Resources