Souza
Souza

Reputation: 1143

Get value from text field input without form

Im trying to send via ajax a value from a textfield, but don't want to use a form , don't think is needed:

name = document.getElementByName["icall"].value;
alert( "Data Saved: " + name );
$.ajax({
type: "GET",
url: "ajaxload/icall.php",
data: "numero="+name
}).done(function( msg ) {
alert( "Data Saved: " + msg );
});

This is the primary function, bellow is the html markup:

<div class="conteudo">
            <span class="numero">O seu numero:</span><input type="text" name="icall" class="teximput" size="30"></input>
            <p><span class="avisome">Precisa de ajuda com algo? Nos ligamos consigo na proxima hora!</span></p>
            <a href="javascript:void(0)" onclick="ligarme();"><span class="botaoliga"></span></a>
        </div>

Shouldn't this be enough?

Upvotes: 0

Views: 8020

Answers (2)

Jacob
Jacob

Reputation: 78860

document.getElementByName["icall"].value

is incorrect. The function is getElementsByName. Also, Instead of square brakets, use parentheses for function calls:

document.getElementsByName("icall")[0].value

Upvotes: 0

Sudhir Bastakoti
Sudhir Bastakoti

Reputation: 100175

Try:

var name = $(".teximput").val();
$.ajax({
type: "GET",
url: "ajaxload/icall.php",
data: "numero="+name,
success:function(msg) {
alert( "Data Saved: " + msg );
});

Upvotes: 2

Related Questions