• CONTEST ALERT - Experience the power of DDR5 memory with Kingston Click for details

Sending dynamically changed price value in URL

Faun

Wahahaha~!
Staff member
7471698726_e507a8f775_b.jpg


I have to update the price for the product in database if I change the price of the product and then click on Change link.

The URL for changing the price is something like this: localhost/muac/edit.php?sku=1234&storeprice=200

I can pick the SKU perfectly from database but picking up changed storeprice (price) is not possible that way since the value is picked from the text field which can be set to any thing at runtime.

How can I get the storeprice value as the value shown in text box, no matter what the value is changed to.

If there is a solution without using Javascript then it will be perfect, but any suggestion is welcome.

Thanks.
 

masterkd

Padawan
if you want to use the jquery way as seen in the screenshot

Code:
storeprice=$('#textboxid').val();
 
OP
Faun

Faun

Wahahaha~!
Staff member
^^thanks I knew that but setting a javascript function for that was kind of new to me. This is what I finally settled to.

And for tracking the changes in price value, I use on .keyup function.

For updating value in text field dynamically at runtime:
PHP:
$(".storeprice").keyup(function(){
	
	val = $(this).val().trim();
	if($(this).val().trim().length < 1)
	{
		
		$(this).attr("class","error");
		$(this).nextUntil("label","span").attr("class","error");
		$(this).nextUntil("label","span").animate({opacity: .2}, 300 );
		$(this).nextUntil("label","span").animate({opacity: 1}, 100 );
		$(this).nextUntil("label","span").animate({opacity: .2}, 300 );
		$(this).nextUntil("label","span").animate({opacity: 1}, 100 );
		$(this).nextUntil("label","span").html("Please enter the info");
		
	}else
	{
		$(this).attr("value",val);
		$(this).attr("class","ok");
		$(this).nextUntil("label","span").attr("class","ok");
		$(this).nextUntil("label","span").html("it is okay now");
	}

})

For sending to a new URL with updated price value:
PHP:
$(".updateprice").click(function(e) {
        e.preventDefault();
        var sku = $(this).next().val();
        
        var storeprice = $(this).prev().val();
       /* $.get('../includes/edit.php',
            {
                sku: sku,
                storeprice: storeprice
            },
            function(data) {
                //"data" is whatever your PHP returns
                console.log(data);
            }
        );*/
		
		var url = "../includes/edit.php?sku="+sku+"&storeprice="+storeprice;
		
		$(location).attr('href',url);
		
    });

And the HTML:
PHP:
<label for="storeprice">Change price:</label>
							<input class="storeprice" id="storeprice" name="storeprice" type="text" size="30" style="width: 70" value="<?php  echo $row->storeprice; ?>" /><a href="#" class="updateprice">Change</a>
							<input type="hidden" name="sku" id="sku" value="<?php  echo $row->sku; ?>" />
<span id="storepriceinfo"  ></span><br />
 
Top Bottom