redbull330
redbull330

Reputation: 666

jquery add input new text but not count as value

I have a button, when click the button add a text inside to input than I write some text too inside the input but i want only get as input value what i entered from keyboard. the keyup and keyCode not work because I enter iso-8859 charecter

$('button').live('click', function() {
$('input').val($('input').val() + $(this).attr("value") );
});

I don't want so...

I want button value showing in input area but not represent as input value and when I get input value,I get only the input value without button value

How can do this?

Upvotes: 0

Views: 652

Answers (1)

Nikos
Nikos

Reputation: 26

if you have a form like this

 <form name='aform' id='myform' action='somescript.php' method='POST'>
 <input type='text' id='txtinput' value='' />
 <input type='button' id='mybutton' name='mybutton' value='My text'/>
 <input type='submit' id='mysubmit' value='submit'/>
 </form>

you can to do this

    <script type="text/javascript">
$(document).ready(function()
    {

    $('#mybutton').click(function(){           
    $('#txtinput').attr('value',$(this).attr('value'));
    });

    $('#mysubmit').click(function(v){            
    var mixinput = $('#txtinput').attr('value');
    var cleaninput =mixinput.replace($('#mybutton').attr('value'),'');
    alert(cleaninput);
    v.preventDefault();
    v.stopPropagation();
    });

    }
    </script>

now it doesn't post just alert u with the value remove v.preventDefault(); v.stopPropagation(); and alert to normaly post the value...

to post values

Upvotes: 1

Related Questions