Prompt recently entered values for forms without getting submitted and not ajax posting to any urls












1















I am running a simple Embedded web-server where a form needs to be filled and the data can be submitted in 3 different ways for a Truck weighing operation. As i am having 3 different buttons to submit the data through an ajax call to a lua webserver i don't want the form gets submitted in default way.



<form id="formTruck" class="form-group">
<label class="form-label" for="reg-num">Rego:</label>
<input class="form-input" type="text" id="rego">
<label class="form-label" for="product">Product:</label>
<input class="form-input" type="text" id="product">
<label class="form-label" for="valuePT">Preset Tare</label>
<input class="form-input" type="text" id="valuePT">
<input id="dump-submit" style="display:none" value="Submit_Dump" type="submit">
</form>
<div id="weighInOutGroup">
<button id="weighIn" onclick="weigh(this.id);">WEIGH IN</button>
<button id="weighOut" onclick="weigh(this.id);">WEIGH OUT</button>
<button id="weighInPt" onclick="weigh(this.id);">WEIGH IN (PT)</button>
</div>


I have JS function to do the ajax request depends on the button clicked



function weigh(type) {
var weighData = {};
if (type == "weighIn") {
$.ajax({
//ajax request
},
});
} else if (type == "weighInPt") {
//ajax request
} else if (type == "weighOut") {
//ajax
}
};


Also i have used following jquery function to prevent pressing enter navigating to default action



$("#formTruck").submit(function(e){     
e.preventDefault();
console.log("weighIn submit prevented")
});


but by doing this i couldn't get the recent inputs prompted on text input fields, as the form is not actually submitted in default action.



Can anyone suggest me a way to achieve this without doing any posts or navigating to any pages?










share|improve this question























  • Just use a form serializer to get the data refer api.jquery.com/serialize/#serialize

    – Pavan Kumar T S
    Jan 3 at 16:48











  • Please add a Minimal, Complete, and Verifiable example which shows the actual problem, because your script works (after fixing the syntax errors): jsbin.com/duyapuroku/edit?html,js,console,output

    – Andreas
    Jan 3 at 16:56


















1















I am running a simple Embedded web-server where a form needs to be filled and the data can be submitted in 3 different ways for a Truck weighing operation. As i am having 3 different buttons to submit the data through an ajax call to a lua webserver i don't want the form gets submitted in default way.



<form id="formTruck" class="form-group">
<label class="form-label" for="reg-num">Rego:</label>
<input class="form-input" type="text" id="rego">
<label class="form-label" for="product">Product:</label>
<input class="form-input" type="text" id="product">
<label class="form-label" for="valuePT">Preset Tare</label>
<input class="form-input" type="text" id="valuePT">
<input id="dump-submit" style="display:none" value="Submit_Dump" type="submit">
</form>
<div id="weighInOutGroup">
<button id="weighIn" onclick="weigh(this.id);">WEIGH IN</button>
<button id="weighOut" onclick="weigh(this.id);">WEIGH OUT</button>
<button id="weighInPt" onclick="weigh(this.id);">WEIGH IN (PT)</button>
</div>


I have JS function to do the ajax request depends on the button clicked



function weigh(type) {
var weighData = {};
if (type == "weighIn") {
$.ajax({
//ajax request
},
});
} else if (type == "weighInPt") {
//ajax request
} else if (type == "weighOut") {
//ajax
}
};


Also i have used following jquery function to prevent pressing enter navigating to default action



$("#formTruck").submit(function(e){     
e.preventDefault();
console.log("weighIn submit prevented")
});


but by doing this i couldn't get the recent inputs prompted on text input fields, as the form is not actually submitted in default action.



Can anyone suggest me a way to achieve this without doing any posts or navigating to any pages?










share|improve this question























  • Just use a form serializer to get the data refer api.jquery.com/serialize/#serialize

    – Pavan Kumar T S
    Jan 3 at 16:48











  • Please add a Minimal, Complete, and Verifiable example which shows the actual problem, because your script works (after fixing the syntax errors): jsbin.com/duyapuroku/edit?html,js,console,output

    – Andreas
    Jan 3 at 16:56
















1












1








1








I am running a simple Embedded web-server where a form needs to be filled and the data can be submitted in 3 different ways for a Truck weighing operation. As i am having 3 different buttons to submit the data through an ajax call to a lua webserver i don't want the form gets submitted in default way.



<form id="formTruck" class="form-group">
<label class="form-label" for="reg-num">Rego:</label>
<input class="form-input" type="text" id="rego">
<label class="form-label" for="product">Product:</label>
<input class="form-input" type="text" id="product">
<label class="form-label" for="valuePT">Preset Tare</label>
<input class="form-input" type="text" id="valuePT">
<input id="dump-submit" style="display:none" value="Submit_Dump" type="submit">
</form>
<div id="weighInOutGroup">
<button id="weighIn" onclick="weigh(this.id);">WEIGH IN</button>
<button id="weighOut" onclick="weigh(this.id);">WEIGH OUT</button>
<button id="weighInPt" onclick="weigh(this.id);">WEIGH IN (PT)</button>
</div>


I have JS function to do the ajax request depends on the button clicked



function weigh(type) {
var weighData = {};
if (type == "weighIn") {
$.ajax({
//ajax request
},
});
} else if (type == "weighInPt") {
//ajax request
} else if (type == "weighOut") {
//ajax
}
};


Also i have used following jquery function to prevent pressing enter navigating to default action



$("#formTruck").submit(function(e){     
e.preventDefault();
console.log("weighIn submit prevented")
});


but by doing this i couldn't get the recent inputs prompted on text input fields, as the form is not actually submitted in default action.



Can anyone suggest me a way to achieve this without doing any posts or navigating to any pages?










share|improve this question














I am running a simple Embedded web-server where a form needs to be filled and the data can be submitted in 3 different ways for a Truck weighing operation. As i am having 3 different buttons to submit the data through an ajax call to a lua webserver i don't want the form gets submitted in default way.



<form id="formTruck" class="form-group">
<label class="form-label" for="reg-num">Rego:</label>
<input class="form-input" type="text" id="rego">
<label class="form-label" for="product">Product:</label>
<input class="form-input" type="text" id="product">
<label class="form-label" for="valuePT">Preset Tare</label>
<input class="form-input" type="text" id="valuePT">
<input id="dump-submit" style="display:none" value="Submit_Dump" type="submit">
</form>
<div id="weighInOutGroup">
<button id="weighIn" onclick="weigh(this.id);">WEIGH IN</button>
<button id="weighOut" onclick="weigh(this.id);">WEIGH OUT</button>
<button id="weighInPt" onclick="weigh(this.id);">WEIGH IN (PT)</button>
</div>


I have JS function to do the ajax request depends on the button clicked



function weigh(type) {
var weighData = {};
if (type == "weighIn") {
$.ajax({
//ajax request
},
});
} else if (type == "weighInPt") {
//ajax request
} else if (type == "weighOut") {
//ajax
}
};


Also i have used following jquery function to prevent pressing enter navigating to default action



$("#formTruck").submit(function(e){     
e.preventDefault();
console.log("weighIn submit prevented")
});


but by doing this i couldn't get the recent inputs prompted on text input fields, as the form is not actually submitted in default action.



Can anyone suggest me a way to achieve this without doing any posts or navigating to any pages?







javascript jquery html ajax






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 3 at 16:41









ThevananthanThevananthan

103




103













  • Just use a form serializer to get the data refer api.jquery.com/serialize/#serialize

    – Pavan Kumar T S
    Jan 3 at 16:48











  • Please add a Minimal, Complete, and Verifiable example which shows the actual problem, because your script works (after fixing the syntax errors): jsbin.com/duyapuroku/edit?html,js,console,output

    – Andreas
    Jan 3 at 16:56





















  • Just use a form serializer to get the data refer api.jquery.com/serialize/#serialize

    – Pavan Kumar T S
    Jan 3 at 16:48











  • Please add a Minimal, Complete, and Verifiable example which shows the actual problem, because your script works (after fixing the syntax errors): jsbin.com/duyapuroku/edit?html,js,console,output

    – Andreas
    Jan 3 at 16:56



















Just use a form serializer to get the data refer api.jquery.com/serialize/#serialize

– Pavan Kumar T S
Jan 3 at 16:48





Just use a form serializer to get the data refer api.jquery.com/serialize/#serialize

– Pavan Kumar T S
Jan 3 at 16:48













Please add a Minimal, Complete, and Verifiable example which shows the actual problem, because your script works (after fixing the syntax errors): jsbin.com/duyapuroku/edit?html,js,console,output

– Andreas
Jan 3 at 16:56







Please add a Minimal, Complete, and Verifiable example which shows the actual problem, because your script works (after fixing the syntax errors): jsbin.com/duyapuroku/edit?html,js,console,output

– Andreas
Jan 3 at 16:56














1 Answer
1






active

oldest

votes


















0














i don't understand why you use 3 send buttons, use instead a radio buttons, in the jquery submit add your if's and for catch the form data use $("#formTruck").serialize()



$("#formTruck").submit(function(e){     

console.log("weighIn submit prevented");

let data = $("#formTruck").serialize() ;

if ($("#rdWeighIn").prop("checked")) {
$.ajax({ data: data, ...
} else if ($("#rdWeighOut").prop("checked")) {
$.ajax({ data: data, ...
} else if ($("#rdWeighInPt").prop("checked")) {
$.ajax({ data: data, ...
} else {
//
}
return false;
});





share|improve this answer
























  • Thanks @imperezivan, I would do that but this is a truck weighing Embedded system application and for the easy operations of the truck drivers the Clients need Three buttons to clearly distinguish the operations. Some how i need Three buttons for the next steps.

    – Thevananthan
    Jan 4 at 4:30












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54026399%2fprompt-recently-entered-values-for-forms-without-getting-submitted-and-not-ajax%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














i don't understand why you use 3 send buttons, use instead a radio buttons, in the jquery submit add your if's and for catch the form data use $("#formTruck").serialize()



$("#formTruck").submit(function(e){     

console.log("weighIn submit prevented");

let data = $("#formTruck").serialize() ;

if ($("#rdWeighIn").prop("checked")) {
$.ajax({ data: data, ...
} else if ($("#rdWeighOut").prop("checked")) {
$.ajax({ data: data, ...
} else if ($("#rdWeighInPt").prop("checked")) {
$.ajax({ data: data, ...
} else {
//
}
return false;
});





share|improve this answer
























  • Thanks @imperezivan, I would do that but this is a truck weighing Embedded system application and for the easy operations of the truck drivers the Clients need Three buttons to clearly distinguish the operations. Some how i need Three buttons for the next steps.

    – Thevananthan
    Jan 4 at 4:30
















0














i don't understand why you use 3 send buttons, use instead a radio buttons, in the jquery submit add your if's and for catch the form data use $("#formTruck").serialize()



$("#formTruck").submit(function(e){     

console.log("weighIn submit prevented");

let data = $("#formTruck").serialize() ;

if ($("#rdWeighIn").prop("checked")) {
$.ajax({ data: data, ...
} else if ($("#rdWeighOut").prop("checked")) {
$.ajax({ data: data, ...
} else if ($("#rdWeighInPt").prop("checked")) {
$.ajax({ data: data, ...
} else {
//
}
return false;
});





share|improve this answer
























  • Thanks @imperezivan, I would do that but this is a truck weighing Embedded system application and for the easy operations of the truck drivers the Clients need Three buttons to clearly distinguish the operations. Some how i need Three buttons for the next steps.

    – Thevananthan
    Jan 4 at 4:30














0












0








0







i don't understand why you use 3 send buttons, use instead a radio buttons, in the jquery submit add your if's and for catch the form data use $("#formTruck").serialize()



$("#formTruck").submit(function(e){     

console.log("weighIn submit prevented");

let data = $("#formTruck").serialize() ;

if ($("#rdWeighIn").prop("checked")) {
$.ajax({ data: data, ...
} else if ($("#rdWeighOut").prop("checked")) {
$.ajax({ data: data, ...
} else if ($("#rdWeighInPt").prop("checked")) {
$.ajax({ data: data, ...
} else {
//
}
return false;
});





share|improve this answer













i don't understand why you use 3 send buttons, use instead a radio buttons, in the jquery submit add your if's and for catch the form data use $("#formTruck").serialize()



$("#formTruck").submit(function(e){     

console.log("weighIn submit prevented");

let data = $("#formTruck").serialize() ;

if ($("#rdWeighIn").prop("checked")) {
$.ajax({ data: data, ...
} else if ($("#rdWeighOut").prop("checked")) {
$.ajax({ data: data, ...
} else if ($("#rdWeighInPt").prop("checked")) {
$.ajax({ data: data, ...
} else {
//
}
return false;
});






share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 3 at 17:02









imperezivanimperezivan

27529




27529













  • Thanks @imperezivan, I would do that but this is a truck weighing Embedded system application and for the easy operations of the truck drivers the Clients need Three buttons to clearly distinguish the operations. Some how i need Three buttons for the next steps.

    – Thevananthan
    Jan 4 at 4:30



















  • Thanks @imperezivan, I would do that but this is a truck weighing Embedded system application and for the easy operations of the truck drivers the Clients need Three buttons to clearly distinguish the operations. Some how i need Three buttons for the next steps.

    – Thevananthan
    Jan 4 at 4:30

















Thanks @imperezivan, I would do that but this is a truck weighing Embedded system application and for the easy operations of the truck drivers the Clients need Three buttons to clearly distinguish the operations. Some how i need Three buttons for the next steps.

– Thevananthan
Jan 4 at 4:30





Thanks @imperezivan, I would do that but this is a truck weighing Embedded system application and for the easy operations of the truck drivers the Clients need Three buttons to clearly distinguish the operations. Some how i need Three buttons for the next steps.

– Thevananthan
Jan 4 at 4:30




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54026399%2fprompt-recently-entered-values-for-forms-without-getting-submitted-and-not-ajax%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas